package cn.bdqn.controller;
import cn.bdqn.bean.result.Page;
import cn.bdqn.bean.result.Result;
import cn.bdqn.bean.result.ResultGenerator;
import cn.bdqn.domain.Purchase;
import cn.bdqn.service.PurchaseService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Purchase)表控制层
 * @author makejava
 * @since 2020-09-21 10:54:13
 */
@RestController
@RequestMapping("/PMS/purchase")
public class PurchaseController {
    /**
     * 服务对象
     */
    @Resource
    private PurchaseService purchaseService;

    /**
     * 通过主键查询单条数据
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public Purchase selectOne(Integer id) {
        return this.purchaseService.queryById(id);
    }

    /**
     * 分页显示
     * 多条件查询数据信息
     */
    @GetMapping("/selectAll")
    public Result selectAll(Integer starNum, Purchase purchase) {
        try{
            Page page=purchaseService.queryAll(starNum,purchase);
            if (page.getMenuList().size()==0){
                return ResultGenerator.genFailResult("没有数据");
            }
            return ResultGenerator.genSuccessResult(page);
        }catch (Exception e){
            e.printStackTrace();
            return ResultGenerator.genFailResult("出现错误");
        }

    }
    /**
     *根据采购表向数据库添加信息
     */
    @PostMapping("/save")
    public void save( @RequestBody Purchase purchase){
        try{
            System.out.println(purchase);
            purchaseService.insert(purchase);
        }catch (Exception e){
            e.printStackTrace();
        }



    }



}